package xyz.xtgl.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;
import xyz.xtgl.oahth2.config.properties.CustomizeProperties;

/**
 * @author liubo
 * @created 2020-01-16 15:22
 */
@Configuration
public class TokenConfig {

    @Bean
    public CustomizeProperties customizeProperties(){
        return new CustomizeProperties();
    }

    // 令牌存储策略
    @Bean
    public TokenStore tokenStore(){
        // Jwt令牌存储方案
        return new JwtTokenStore(jwtAccessTokenConverter());
    }

    @Bean
    public JwtAccessTokenConverter jwtAccessTokenConverter(){
        JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
        converter.setSigningKey(customizeProperties().getOauth2().getJwt().getSigningKey());//
        return converter;
    }
}
